﻿using System;
using System.Collections.Generic;

namespace Conv
{
    public class FullConnectedLayer:Layer
    {
        //private readonly Func<double, double> _activationFunc = x =>  Math.Tanh(x);//WARNING experimetal coeffs
        //private readonly Func<double, double> _activationFuncDerivative = x => 1 - (1.7159 * Math.Tanh(x)) * (1.7159 * Math.Tanh(x));
        //private readonly Func<double, double> _activationFunc = x => Math.Tanh(x);
        //private readonly Func<double, double> _activationFuncDerivative = x => 
        //    1 - Math.Tanh(x) * Math.Tanh(x);
        private readonly Func<double, double> _activationFunc =  x => 1.7159 * Math.Tanh(x * 2 / 3);
        private readonly Func<double, double> _activationFuncDerivative = x =>
            -1.44 * Math.Tanh(2 * x / 3) * Math.Tanh(2 * x / 3) + 1.44;
        
        public FullConnectedLayer(List<Layer> mapList,int neuronCount)
        {
            Neurons = new Neuron[neuronCount,1];
            Width = neuronCount;
            Height = 1;
            for (int i = 0; i < neuronCount; i++)
            {
                Neurons[i,0] = new Neuron(){ActivationFunc = _activationFunc,ActivationFuncDerivative = _activationFuncDerivative};
                foreach (Layer map in mapList)
                {
                    ConnectLayerToNeuron(Neurons[i,0],map);
                }
            }

        }
        private void ConnectLayerToNeuron(Neuron neuron, Layer layer)
        {
            foreach (Neuron n in layer.Neurons)
            {
                neuron.Inputs.Add(new Connection(){From = n,To = neuron,Weight = new Weight()});
            }
        }
    }
}